package com.cookie.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "mysql.conf")
public class MysqlConfig {
    private String driver = "com.mysql.cj.jdbc.Driver";
    private final String params =
            "?useUnicode=true&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=UTC";
    private String url;
    private String username;
    private String password;
    // 这里最好大于等于可用线程数，否则多线程时，会有线程无法获得可用连接，导致出现连接超时
    // 但不确定可用线程数的大小，于是就把超时时间改为了-1
    private Integer maxActive = 6;  // 连接池最大连接数，默认为3

    public String getDriver() {
        return driver;
    }

    public void setDriver(String driver) {
        this.driver = driver;
    }
    // 给url补上一系列参数
    public String getUrl() {
        return url+params;
    }

    public void setUrl(String url) {
        this.url = url+params;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getMaxActive() {
        return maxActive;
    }

    public void setMaxActive(Integer maxActive) {
        this.maxActive = maxActive;
    }

    @Override
    public String toString() {
        return "MysqlConfig{" +
                "driver='" + driver + '\'' +
                ", url='" + url + '\'' +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", maxActive=" + maxActive +
                '}';
    }
}
